package com.midipad.controls;

import com.midipad.R;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.MotionEvent;
/**
 * A 2D pad
 * @author Tim
 *
 */
public class Pad extends MidiController {
	
	public Pad(Context context, int x, int y, int width, int height, int[] midiMessages){//default size constructor
		super(context, 2, "Pad", x, y, width, height, midiMessages);
		//set up background
		this.setBackgroundDrawable(getResources().getDrawable(R.drawable.back_pad_9p));
	}

	@Override 
	protected void onDraw(Canvas canvas) {
		Paint paint = new Paint();
		paint.setStyle(Paint.Style.FILL);
		paint.setColor(Color.WHITE);
		canvas.drawLine(0, values[1], width, values[1], paint);
		canvas.drawLine(values[0], 0, values[0], height, paint);
		paint.setColor(Color.RED);
		canvas.drawText(midiValues[0]+"/"+midiValues[1], width/2, height/2, paint);
	}

	@Override
	public void updateValues(int x, int y, MotionEvent me){
		values[0] = x;
		values[1] = y;
		midiValues[0] = values[0]*MAX_MIDI_MSG_VAL/width;
		midiValues[1] = MAX_MIDI_MSG_VAL-(values[1]*MAX_MIDI_MSG_VAL/height);
	}

	@Override
	public void setValues(int val1, int val2, int val3) {
		if(val1==midiMessages[0] && val2==midiMessages[2]){
			values[0] = val3*width/MAX_MIDI_MSG_VAL;
		}else{
			values[1] = val3*height/MAX_MIDI_MSG_VAL;
		}
	}
}
